package com.ext.aic.apis.attachment;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.params.AttachmentConfirmParams;
import com.ext.aic.beans.response.AttachmentConfirmResponse;
import com.eyinfo.android_pure_utils.utils.JsonUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.body.JsonRequestBody;

public class AttachmentConfirmRequest {

    private int count = 0;

    protected void onAttachmentConfirmResponseSuccess(AttachmentConfirmResponse response) {

    }

    protected void onAttachmentConfirmResponseFail(Throwable throwable, AttachmentConfirmParams params) {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, AttachmentConfirmParams params) {
        EasyHttp.post(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.attachmentConfirm))
                .body(new JsonRequestBody(JsonUtils.toJson(params)))
                .request(new RequestResponse<AttachmentConfirmResponse>(context, false) {
                    @Override
                    protected void onSuccess(AttachmentConfirmResponse response) {
                        onAttachmentConfirmResponseSuccess(response);
                    }

                    @Override
                    public void onHttpFail(Throwable throwable) {
                        onAttachmentConfirmResponseFail(throwable, params);
                        count++;
                        if (count < 3) {
                            request(context, lifecycleOwner, params);
                        }
                    }
                });
    }
}
